package com.config;


import org.springframework.web.servlet.handler.HandlerInterceptorAdapter;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.Objects;

/**
 * @author   csm
 * @data 2020-09-2020/9/7-16:17
 * @desc    后台拦截器
 */
public class AdminInterceptor extends HandlerInterceptorAdapter {

    @Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object hand)throws  Exception{
        String uri=request.getRequestURI();
        if (uri.contains("img") || uri.contains("css") || uri.contains("js") || uri.contains("login")|| uri.contains("logout")){
            return true;

        }

            Object admin =request.getSession().getAttribute("admin");
        if (Objects.nonNull(admin) && !admin.toString().trim().isEmpty()){
            return  true;
        }
        response.sendRedirect("login.jsp");
        return  false;

    }

}